package com.xcity.db.entity;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.guild.gevent.GuildEvents;
import com.xcity.util.IdUtils;

import naga.x.common.Initializable;

public class Guild implements Initializable{
	
	public static Logger LOG = LoggerFactory.getLogger(Guild.class);
	
	private long id;
	private String name;
	private Date createTime;
	private long chairmanId;//会长ID
	
	private int flag;
	private String slogan;
	private int exp;
	private byte joinType;//0允许任何人加入 1需要申请 2拒绝任何人
	private int memCount;
	
	private GuildEvents gevent;
	private byte joinLvl;//入会所需要的等级限制 0:无限制
	
	public static int JOIN_TYPE_FREE = 0;			//入会方式 允许任何人入会
	public static int JOIN_TYPE_NEED_APPLY = 1;		//需要申请
	public static int JOIN_TYPE_NONE_SHALL_PASS = 2;		//拒绝任何人
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public long getChairmanId() {
		return chairmanId;
	}
	public void setChairmanId(long chairmanId) {
		this.chairmanId = chairmanId;
	}
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}	
	public String getSlogan() {
		return slogan;
	}
	public void setSlogan(String slogan) {
		this.slogan = slogan;
	}
	public int getExp() {
		return exp;
	}
	public void setExp(int exp) {
		this.exp = exp;
	}
	
	public byte getJoinType() {
		return joinType;
	}
	public void setJoinType(byte joinType) {
		this.joinType = joinType;
	}
	
	public int getMemCount() {
		return memCount;
	}
	public void setMemCount(int memCount) {
		this.memCount = memCount;
	}
	
	public GuildEvents getGevent() {
		return gevent;
	}
	public void setGevent(GuildEvents gevent) {
		this.gevent = gevent;
	}
	public byte getJoinLvl() {
		return joinLvl;
	}
	public void setJoinLvl(byte joinLvl) {
		this.joinLvl = joinLvl;
	}
	public Guild(){
	}
	
	public Guild(long chairManId, String name){
		this.id = IdUtils.nextGuildId();
		this.name = name;
		this.chairmanId = chairManId;
		this.createTime = new Date();
		this.exp = 0;
		this.joinType = 0;
		this.joinLvl = 0;
		this.gevent = new GuildEvents(null);
	}
	
	public boolean addExp(int val, String cause){
		int oldVal = getExp();
		if(val <= 0 || oldVal + val <= 0){
			return false;
		}
		int newVal = this.exp + val;
		this.exp = newVal;
		LOG.info("[ADDGUILDEXP]ID[{}]OLD[{}]NEW[{}]CAUSE[{}]", id, oldVal, newVal, cause);
		return true;
	}
	@Override
	public void init() {
		if(gevent == null){
			gevent = new GuildEvents(null);
		}
	}
}
